<?php Cookie::set(Admincp::$APP_NAME . '_tabs', $this->tabs); ?>
<?php self::head(); ?>
<script type="text/javascript">
    iCMS.set('Vue.data', {
        st: "<?php echo $_GET['st']; ?>",
        status: "<?php echo $_GET['status']; ?>",
        orderby: "<?php echo $_GET['orderby'] ?: 'id DESC'; ?>",
        rootid: "<?php echo isset($_GET['rootid']) ? $_GET['rootid'] : '-1'; ?>",
    }).set('batch', {
        move: function() {
            return $("#mergeBatch").html();
        }
    });
</script>
<div class="content" id="<?php echo APP_MAINID; ?>">
    <div class="block">
        <?php include self::view($this->VIEW_MANAGE . '_nav', $this->VIEW_DIR); ?>
        <div class="block-content block-content-full">
            <form action="<?php echo iPHP_SELF; ?>" method="get">
                <input type="hidden" name="appid" value="<?php echo $this->app_id; ?>" />
                <input type="hidden" name="app" value="<?php echo Admincp::$APP_NAME; ?>" />
                <input type="hidden" name="do" value="<?php echo Admincp::$APP_DO; ?>" />
                <div class="form-row">
                    <div class="input-group input-group-sm col-sm-6 col-md-4 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="rootid">父<?php echo $this->NODE_NAME; ?></label>
                        </div>
                        <select v-model="rootid" class="form-control" name="rootid" id="rootid">
                            <option value="">所有<?php echo $this->NODE_NAME; ?></option>
                            <option value="0">=====顶级<?php echo $this->NODE_NAME; ?>=====</option>
                            <?php echo $node_select = Node::setAccess('m')->select(array('url' => true)); ?>
                        </select>
                    </div>
                    <div class="input-group input-group-sm col-sm-6 col-md-4 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="status">状态</label>
                        </div>
                        <select v-model="status" name="status" id="status" class="form-control">
                            <option value="">全部</option>
                            <?php echo PropWidget::option(Node::$statusMap, "status"); ?>
                        </select>
                    </div>
                    <div class="input-group input-group-sm col-sm-6 col-md-4 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="st">查找方式</label>
                        </div>
                        <select v-model="st" name="st" id="st" class="form-control">
                            <option value=""></option>
                            <option value="name"><?php echo $this->NODE_NAME; ?>名</option>
                            <option value="id">CID</option>
                            <option value="dir">目录</option>
                            <option value="appid">APPID</option>
                            <option value="tkd">标题/关键字/简介</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm col-sm-6 col-md-4 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="orderby">排序</label>
                        </div>
                        <select v-model="orderby" name="orderby" id="orderby" class="form-control">
                            <option value="">默认排序</option>
                            <optgroup label="降序"><?php echo self::$orderBy['DESC']; ?></optgroup>
                            <optgroup label="升序"><?php echo self::$orderBy['ASC']; ?></optgroup>
                        </select>
                    </div>
                    <div class="input-group input-group-sm col-sm-6 col-md-4 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="pageSize">每页</label>
                        </div>
                        <input class="form-control" type="text" name="pageSize" id="pageSize" value="<?php echo Paging::$pageSize; ?>" />
                        <div class="input-group-append">
                            <label class="input-group-text" for="pageSize">条记录</label>
                        </div>
                    </div>
                    <div class="input-group input-group-sm col-sm-6 col-md-4 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="keywords">关键字</label>
                        </div>
                        <input type="text" name="keywords" class="form-control" id="keywords" value="<?php echo $_GET['keywords']; ?>" />
                        <div class="input-group-append">
                            <button class="btn btn-primary" type="submit"><i class="fa fa-fw fa-search"></i> 搜 索</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="block">
        <div class="block-header">
            <h3 class="block-title"><?php echo $this->NODE_NAME; ?>列表</h3>
            <div class="block-options">
                <button type="button" class="btn-block-option" data-toggle="block-option" data-action="fullscreen_toggle"><i class="si si-size-fullscreen"></i></button>
                <button type="button" class="btn-block-option" data-toggle="block-option" data-action="content_toggle"><i class="si si-arrow-up"></i></button>
                <!-- <button type="button" class="btn-block-option" data-toggle="block-option" data-action="close">
                    <i class="si si-close"></i>
                </button> -->
            </div>
        </div>
        <div class="block-content p-0">
            <form action="<?php echo $this->NODE_URL; ?>&do=batch" method="POST" id="<?php echo APP_FORMID; ?>" target="iPHP_FRAME">
                <div class="table-responsive">
                    <table class="dataTable table text-nowrap table-hover table-striped table-vcenter font-size-sm mb-0">
                        <thead class="bg-light text-black">
                            <tr>
                                <th style="width: 36px;" class="align-middle">
                                    <div class="custom-control custom-checkbox">
                                        <input type="checkbox" class="custom-control-input" id="check-all" data-toggle="checkAll" data-target="#<?php echo APP_FORMID; ?>">
                                        <label class="custom-control-label" for="check-all"></label>
                                    </div>
                                </th>
                                <th style="width: 60px;">CID</th>
                                <th class="sorting" style="width: 80px;">排序</th>
                                <th><?php echo $this->NODE_NAME; ?>名</th>
                                <th>目录</th>
                                <th style="width: 90px;">父<?php echo $this->NODE_NAME; ?></th>
                                <?php if (Admincp::$APP_NAME == 'node') { ?>
                                    <th>APPID</th>
                                <?php } ?>
                                <th style="width: 70px;">数据</th>
                                <th class="text-center">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $rootidArray = array_column($result, 'rootid');
                            $rootidArray && $root_data = (array) Node::get($rootidArray);
                            // var_dump($root_data);
                            if ($result) foreach ($result as $key => $value) {
                                $root = $root_data[$value['rootid']];
                                $rootName = $root ? $root['name'] : '顶级' . $this->NODE_NAME;
                            ?>
                                <tr id="id<?php echo $value['id']; ?>" class="status<?php echo $value['status']; ?>">
                                    <td>
                                        <div class="custom-control custom-checkbox">
                                            <input type="checkbox" class="custom-control-input" id="checkbox-<?php echo $value['id']; ?>" name="id[]" value="<?php echo $value['id']; ?>" />
                                            <label class="custom-control-label" for="checkbox-<?php echo $value['id']; ?>"></label>
                                        </div>
                                    </td>
                                    <td><a href="<?php echo Route::get('node', $value)->href; ?>" target="_blank"><?php echo $value['id']; ?></a></td>
                                    <td><input class="form-control form-control-sm" type="text" name="sortnum[<?php echo $value['id']; ?>]" value="<?php echo $value['sortnum']; ?>" /></td>
                                    <td><input class="form-control form-control-sm" <?php if ($value['rootid'] == "0") { ?> style="font-weight:bold" <?php } ?> type="text" name="name[<?php echo $value['id']; ?>]" value="<?php echo $value['name']; ?>">
                                        <?php if (!$value['status']) { ?>
                                            <i class="fa fa-fw fa-eye-slash" title="隐藏<?php echo $this->NODE_NAME; ?>"></i>
                                        <?php } ?>
                                        <?php $value['pid'] && PropWidget::flag($value['pid'], 'pid'); ?>
                                    </td>
                                    <td><input class="form-control form-control-sm" type="text" name="dir[<?php echo $value['id']; ?>]" value="<?php echo $value['dir']; ?>" /></td>
                                    <td><a href="<?php echo APP_DOURL; ?>&rootid=<?php echo $value['rootid']; ?>"><?php echo $rootName ?></a></td>
                                    <?php if (Admincp::$APP_NAME == 'node') { ?>
                                        <td><a href="<?php echo APP_DOURL; ?>&appid=<?php echo $value['appid']; ?>"><?php echo $value['appid']; ?></a></td>
                                    <?php } ?>
                                    <td><span class="badge badge-primary"><?php echo $value['count']; ?></span></td>
                                    <td class="text-right">
                                        <div class="btn-group btn-group-sm">
                                            <?php if (NodeAccess::check($value['id'], 'a')) { ?>
                                                <a class="btn btn-alt-primary" href="<?php echo $this->NODE_URL; ?>&do=add&rootid=<?php echo $value['id']; ?>" title='添加子<?php echo $this->NODE_NAME; ?>'><i class="fa fa-fw fa-plus-square"></i></a>
                                            <?php } ?>
                                            <?php if (NodeAccess::check($value['id'], 'ca')) { ?>
                                                <a class="btn btn-alt-primary" href="<?php echo ADMINCP_URL; ?>=<?php echo $this->app; ?>&do=add&<?php echo $this->primary; ?>=<?php echo $value['id']; ?>" title='添加<?php echo $this->title; ?>'><i class="fa fa-fw fa-pencil-alt"></i> </a>
                                            <?php } ?>
                                            <?php if (NodeAccess::check($value['id'], 'cm')) { ?>
                                                <a class="btn btn-alt-primary" href="<?php echo ADMINCP_URL; ?>=<?php echo $this->app; ?>&<?php echo $this->primary; ?>=<?php echo $value['id']; ?>&sub=on" title='<?php echo $this->title; ?>管理'><i class="fa fa-fw fa-list-alt"></i></a>
                                            <?php } ?>
                                            <?php if (NodeAccess::check($value['id'], 'e')) { ?>
                                                <a class="btn btn-alt-primary" href="<?php echo $this->NODE_URL; ?>&do=<?php echo $value['id']; ?>" target="iPHP_FRAME" title='克隆'><i class="fa fa-fw fa-clipboard"></i></a>
                                                <a class="btn btn-alt-primary" href="<?php echo $this->NODE_URL; ?>&do=edit&id=<?php echo $value['id']; ?>" title='编辑'><i class="fa fa-fw fa-pencil-alt"></i> </a>
                                            <?php } ?>
                                            <?php if (NodeAccess::check($value['id'], 'd')) { ?>
                                                <a class="btn btn-alt-primary" href="<?php echo $this->NODE_URL; ?>&do=delete&id=<?php echo $value['id']; ?>" target="iPHP_FRAME" title='永久删除' data-action="delete" /><i class="fa fa-fw fa-times"></i></a>
                                    </td>
                                <?php } ?>
                                </tr>
                            <?php }  ?>
                        </tbody>
                    </table>
                </div>
                <?php self::formFoot(); ?>
            </form>
        </div>
    </div>
</div>
<div class='iCMS-batch'>
    <div id="modeBatch">
        <div class="form-group">
            <label class="col-form-label" for="bmode">访问模式</label>
            <select class="form-control" name="bmode" id="bmode">
                <option value="0">动态</option>
                <option value="1">静态</option>
                <option value="2">伪静态</option>
            </select>
        </div>
    </div>
    <div id="dirBatch">
        <div class="form-group">
            <label class="col-form-label" for="bmdir">目录</label>
            <input type="text" class="form-control" name="bdir" id="bmdir" />
        </div>
        <div class="form-group">
            <div class="custom-control custom-radio custom-control-inline">
                <input type="radio" class="custom-control-input" name="pattern" id="pattern_1" value="addtobefore" />
                <label class="custom-control-label" for="pattern_1">前追加</label>
            </div>
            <div class="custom-control custom-radio custom-control-inline">
                <input type="radio" class="custom-control-input" name="pattern" id="pattern_2" value="addtoafter" />
                <label class="custom-control-label" for="pattern_2">后追加</label>
            </div>
            <div class="custom-control custom-radio custom-control-inline">
                <input type="radio" class="custom-control-input" name="pattern" id="pattern_3" value="replace" checked />
                <label class="custom-control-label" for="pattern_3">替换</label>
            </div>
        </div>
    </div>
    <div id="mergeBatch">
        <div class="form-group">
            <label class="col-form-label" for="tonid">请选择目标<?php echo $this->NODE_NAME; ?></label>
            <select id="tonid" name="tonid" class="form-control">
                <option value="0">===顶级<?php echo $this->NODE_NAME; ?>===</option>
                <?php echo $node_select; ?>
            </select>
        </div>
    </div>
    <div id="appidBatch">
        <div class="form-group">
            <label class="col-form-label" for="toappid">请选择所属应用</label>
            <select id="toappid" name="toappid" class="form-control">
                <option value="0">无应用[appid='0']</option>
                <?php foreach (Apps::getTableArray() as $key => $value) { ?>
                    <option value="<?php echo $value['id']; ?>">
                        <?php echo $value['app']; ?>:
                        <?php echo $value['name']; ?> [appid=
                        <?php echo $value['id']; ?>]</option>
                <?php } ?>
            </select>
        </div>
    </div>
    <div id="statusBatch">
        <div class="form-group">
            <label class="col-form-label" for="bstatus">栏目状态</label>
            <select id="bstatus" name="bstatus" class="form-control">
                <?php echo PropWidget::option(Node::$statusMap, "status"); ?>
            </select>
        </div>
    </div>
    <div id="ruleBatch">
        <?php $s = array("rule" => true); ?>
        <?php include self::view('node.route', $this->VIEW_DIR); ?>
    </div>
    <div id="templateBatch">
        <?php $s = array("tpl" => true); ?>
        <?php include self::view('node.route', $this->VIEW_DIR); ?>
    </div>
</div>
<?php self::foot(); ?>